<?php

/**************************************************************************
* Source File	:  Administrateur.php
* Author                   :  Marian
* Project name         :  Accueil Win'Design version 14* Created                 :  20/01/2015
* Modified   	:  20/01/2015
* Description	:  Definition of the class Administrateur
**************************************************************************/




class Administrateur 			
{
	//Attributes
		
	private $idA;
	Private $nomA;
	Private $prenomA;
	Private $fonctionA;
	Private $telportA;
	Private $emailA;
	Private $loginA; 
	Private $mdpA;
	private $photoprofil; 

	//Operations
	public function __set($propriete, $valeur) {
	
		switch ($propriete) {
			
			case 'idA' : {
				$this->idA = $valeur;
				break;
			}
			
			case 'nomA' : {
				$this->nomA = $valeur;
				break;
			}
	
			case 'prenomA' : {
				$this->prenomA = $valeur;
				break;
			}
				
			case 'fonctionA' : {
				$this->fonctionA = $valeur;
				break;
			}
			
			case 'emailA' : {
				$this->emailA = $valeur;
				break;
			}
			
			case 'loginA' : {
				$this->loginA = $valeur;
				break;
			}
			
			case '$mdpA' : {
				$this->mdpA = $valeur;
				break;
			}
		}
	}

	public function __construct($vloginA, $vmdpA)
	{	
		$PrepREQ = $this->PDO();
		$ID = $PrepREQ->TrouverID($vloginA, $vmdpA);
		//SI il existe un admin avec pour login : $vloginA et pour mdp : $vmdpa alors on créer l'administrateur en fonction de la BDD
		if ($ID != false)
		{
			
			$this->idA = $ID['ADMIN_ID'];
			$this->loginA = $vloginA;
			$this->mdpA = $vmdpA;
			$profil = $PrepREQ->SelectById($ID['ADMIN_ID']);
			$this->nomA = $profil[0]['ADMIN_NOM'];
			$this->prenomA = $profil[0]['ADMIN_PRENOM'];
			$this->fonctionA = $profil[0]['ADMIN_FONCTION'];
			$this->telportA = $profil[0]['ADMIN_TEL'];
			$this->emailA = $profil[0]['ADMIN_EMAIL'];
			
			
			
			
		}
		//Sinon
		else
		{
			$this->loginA = $vloginA;
			$this->mdpA = $vmdpA;
		}
		
	}
	
	public function PDO ()
	{
		require_once (dirname(dirname(__FILE__)).'/MyPDO.php');
		require_once ('PreparationREQAdministrateur.php');
		$PrepREQ = new PreparationREQAdministrateur(new MyPDO());
		return $PrepREQ;
	}
	
	public function TrouverID()
	{
		$PrepREQ = $this->PDO();
		$Result[] = $PrepREQ->TrouverID($this->loginA, $this->mdpA);
		return $Result;
	}
	
	public function Modifier($vnouvnom, $vnouvprenom, $vnouvtel, $vnouvemail)
	{
		$PrepREQ = $this->PDO();
		$ok = $PrepREQ->UpdateAllById($vnouvnom, $vnouvprenom, $vnouvtel, $vnouvemail, $this->idA);
		return $ok;
	}
	
	public function Arrayprofil()
	{
		$vretour=array();
		if ((isset($this->idA)) && ($this->idA != NULL))
		{
		$vretour = array("ID"=>$this->idA, "Nom"=>$this->nomA, "Prenom"=>$this->prenomA, "Fonction"=>$this->fonctionA, "Tel"=>$this->telportA, "Email"=>$this->emailA);
		}
		else
		{
		$vretour = array("ID"=>-1);
		}
		return $vretour;
	}
	
	public function GetIdentifiants()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->SelectIdentifiantsById($this->idA);
	}
	
	public function CreerAdministrateur($newlogin, $newmdp)
	{
		$PrepREQ = $this->PDO();
		$PrepREQ->insert($newlogin, $newmdp);
	}
	
	public function Getphotoprofil()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->SelectPhotoProfilByAdminId($this->idA);
	}
	/*public UpdatePhotoProfil()
	{
		$PrepREQ = $this->PDO();
		return $PrepREQ->
	}*/
	

} // End Class Administrateur


?>

